package com.aldobucchi.x.String
{
 
 	import com.aldobucchi.utils.AbstractTest;
 	
 	
 	
 	/**
 	 * 
 	 * @private
 	 * 
 	 * @author aldo.bucchi@gmail.com
 	 * 
 	 */ 	
 	public class StringUtilTest extends AbstractTest
 	{



		public function testDecodeUnicode( ):void
		{
			
			assertEquals( "Dürst", StringUtil.decodeUnicode( "D\\u00FCrst" ) );
			// TODO: throw in some more tests here...
		}  		


		
		public function test_findFirstQuotePair( ):void
		{
			
			assertNull(  StringUtil.findFirstQuotePair( 'there are no quotes here' ) );
			
			assertContainersEqual(
				StringUtil.findFirstQuotePair( 'there "are quotes" here' ) ,
				[ 6, 17 ]
				);


			assertContainersEqual(
				StringUtil.findFirstQuotePair( 'there "are \\"quotes" here' ) ,
				[ 6, 19 ] // we add only two, remember the escape
				);				
			
		}






  		public function testRemoveSection():void
  		{
  			
  			var str:String = "0123456789";
  			
   			assertTrue( "Expecting 123456789", StringUtil.removeSection( str, 0, 0 ) == "123456789" );
   			assertTrue( "Expecting 0123489", StringUtil.removeSection( str, 5, 7 ) == "0123489" );
   			assertTrue( "Expecting ''", StringUtil.removeSection( str, 0, 9 ) == "" );
   			
   			// out of bounds
   			assertTrue( "Expecting ''", StringUtil.removeSection( str, 0, 20 ) == "" );
   			assertTrue( "Expecting 0123456789", StringUtil.removeSection( str, 10, 20 ) == "0123456789" );
   			
   			// illegal
   			assertTrue( "Expecting 0123456789", StringUtil.removeSection( str, 4, 0 ) == "0123456789" );
   			
   		}


		public function testTrimEdges():void
		{
			var str:String = "1234567890987654321";
			assertTrue( "trim 1 = 23456789098765432", StringUtil.trimEdges( str, 1 ) == "23456789098765432" );
			assertTrue( "trim 2 = 345678909876543", StringUtil.trimEdges( str, 2 ) == "345678909876543" );
			assertTrue( "trim 9 = 0", StringUtil.trimEdges( str, 9 ) == "0" );
			
			// border cases
			assertTrue( "trim 0 = 1234567890987654321", StringUtil.trimEdges( str, 0 ) == "1234567890987654321" );
			assertTrue( "trim 10 = ''", StringUtil.trimEdges( str, 10 ) == "" );
			
			// invalid values
			assertTrue( "trim 30 = ''", StringUtil.trimEdges( str, 30 ) == "" );
			assertTrue( "trim -8 = 1234567890987654321 ''", StringUtil.trimEdges( str, -8 ) == "1234567890987654321" );
			
			
			
			
		} 
   		
  		
  	}
}